import java.util.Random;

public class CaptchaGenerator {

    public static void main(String[] args) {
        String captcha = generateCaptcha(4);
        System.out.println("验证码: " + captcha);
    }

    public static String generateCaptcha(int length) {
        String characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
        Random random = new Random();
        StringBuilder captcha = new StringBuilder();
        for (int i = 0; i < length; i++) {
            int index = random.nextInt(characters.length());
            char c = characters.charAt(index);
            captcha.append(c);
        }
        return captcha.toString();
    }
}